package cn.imokay.entity;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@Data
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode
@Accessors(chain = true)
public class Author implements Comparable<Author>{
    private Long id;
    private String name;
    private Integer age;
    private String intro;
    private List<Book> books;

    public static List<Author> getAuthors() {
        Author author1 = new Author(1L, "张三", 18, "作家张三", null);
        Author author2 = new Author(2L, "李四", 17, "作家李四", null);
        Author author3 = new Author(3L, "王五", 16, "作家王五", null);
        Author author4 = new Author(4L, "赵六", 28, "作家赵六", null);

        ArrayList<Book> books1 = new ArrayList<>();
        ArrayList<Book> books2 = new ArrayList<>();
        ArrayList<Book> books3 = new ArrayList<>();
        ArrayList<Book> books4 = new ArrayList<>();

        books1.add(new Book(1L,"张三作品1","漫画,哲学",89,"张三的作品1"));
        books1.add(new Book(2L,"张三作品2","战争,经济",86,"张三的作品2"));

        books2.add(new Book(1L,"李四作品1","政治,小说",80,"李四的作品1"));
        books2.add(new Book(2L,"李四作品2","散文,自传",83,"李四的作品2"));
        books2.add(new Book(3L,"李四作品3","历史,小说",93,"李四的作品3"));

        books3.add(new Book(1L,"王五作品1","文学,战争",97,"王五的作品1"));
        books3.add(new Book(2L,"王五作品2","经济",93,"王五的作品2"));
        books3.add(new Book(3L,"王五作品3","数学,哲学",63,"王五的作品3"));

        books4.add(new Book(1L,"赵六作品1","理论物理,哲学",85,"赵六的作品1"));
        books4.add(new Book(2L,"赵六作品2","应用物理",84,"赵六的作品2"));
        books4.add(new Book(3L,"赵六作品3","有机化学,制药",99,"赵六的作品3"));

        author1.setBooks(books1);
        author2.setBooks(books2);
        author3.setBooks(books3);
        author4.setBooks(books3);

        return new ArrayList<>(Arrays.asList(author1,author2,author3,author4));
    }

    @Override
    public int compareTo(Author o) {
        return this.getAge() - o.getAge();
    }
}


